package com.yty.order.controller;

import com.yty.order.exception.OrderRuntimeException;
import com.yty.order.form.OrderForm;
import com.yty.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(tags = "订单")
@RequestMapping("com/yty/order")
@RestController
public class OrderController {
    @Resource
    private OrderService orderService;

    @ApiOperation("创建订单")
    @PostMapping("create")
    public void create(@Valid @RequestBody OrderForm orderForm, BindingResult bindingResult) {
        if (bindingResult.hasErrors())
            throw new OrderRuntimeException(bindingResult.getFieldError().getDefaultMessage());
        orderService.create(orderForm);
    }
}
